<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<lv-form [formGroup]="formGroup" class="formGroup" [ngClass]="{'limit-input-width':showDatabaseTable}">
  <!-- 恢复位置 -->
  <lv-form-item>
    <lv-form-label lvRequired>
      {{ 'protection_restore_to_label' | i18n }}
    </lv-form-label>
    <lv-form-control>
      <lv-radio-group formControlName="restoreLocation">
        <lv-group [lvGutter]="'24px'">
          <lv-radio
            [lvValue]="restoreLocationType.ORIGIN"
            [lvDisabled]="disableOriginLocation"
            [lv-tooltip]="
              disableOriginLocation
                ? ('protection_cloud_origin_restore_disabled_label' | i18n)
                : ''
            "
          >
            {{ 'common_restore_to_origin_location_label' | i18n }}
          </lv-radio>
          <lv-radio [lvValue]="restoreLocationType.NEW">
            {{ 'common_restore_to_new_location_label' | i18n }}
          </lv-radio>
        </lv-group>
      </lv-radio-group>
    </lv-form-control>
  </lv-form-item>

  <!-- 目标单机/可用性组 -->
  <ng-container
    *ngIf="formGroup.value.restoreLocation === restoreLocationType.ORIGIN"
  >
    <lv-form-item>
      <lv-form-label lvRequired>
        {{ 'protection_single_system_ang_dag_label' | i18n }}
      </lv-form-label>
      <lv-form-control>
        <input lv-input type="text" formControlName="originLocation"/>
      </lv-form-control>
    </lv-form-item>
  </ng-container>

  <!-- 新位置选择路径 -->
  <ng-container
    *ngIf="formGroup.value.restoreLocation === restoreLocationType.NEW"
  >
    <lv-form-item>
      <lv-form-label lvRequired>
        {{ 'protection_single_system_ang_dag_label' | i18n }}
      </lv-form-label>
      <lv-form-control>
        <lv-select
          lvShowFilter
          lvFilterKey="label"
          lvFilterMode="contains"
          formControlName="host"
          [lvOptions]="hostAndDAGOptions"
          lvValueKey="value"
          [ngClass]="{'input-width':showDatabaseTable}"
        >
        </lv-select>
      </lv-form-control>
    </lv-form-item>

  </ng-container>



  <!-- 选择需要恢复的邮箱服务器(数据库细粒度恢复)-->
  <lv-group lvDirection="vertical" lvGutter="20px" style="margin-top: 10px" *ngIf="showDatabaseTable">
    <div>
      <h2>{{'protection_exchange_restore_select_mailbox_label'|i18n}}</h2>
    </div>
    <div style="height: 55vh">
      <lv-transfer
        #lvTransfer
        lvAsync="true"
        lvDataKey="key"
        lvColDisplayControl="false"
        [lvSourceColumns]="sourceColumns"
        [lvSourceData]="sourceData"
        [lvSourceSelection]="sourceSelection"
        [lvTargetColumns]="targetColumns"
        (lvSelectionChange)="selectionChange($event)"
        [lvItemSize]="commonConsts.PAGE_SIZE_MAX"
        [lvFooters]="[pageS,pageT]"
      >
      </lv-transfer>
    </div>
  </lv-group>

  <ng-template #pageS>
    <lv-paginator lvShowPageSizeOptions="false" [lvPageSize]="commonConsts.PAGE_SIZE_MAX" [lvTotal]="totalPage" (lvPageChange)="sourcePageChange($event)">

    </lv-paginator>
  </ng-template>

  <ng-template #pageT>
    <lv-paginator lvShowPageSizeOptions="false" [lvTotal]="selectionData.length" [lvPageSize]="commonConsts.PAGE_SIZE_MAX">
    </lv-paginator>
  </ng-template>

  <!-- 高级配置 -->
  <div class="advanced-container">
    <lv-collapse [lvType]="'simple'">
      <lv-collapse-panel [lvTitle]="titleTpl" [lvExpanded]="false">
        <lv-form-item>
          <lv-form-label>
            {{ 'protection_restore_pre_script_label' | i18n }}
            <i lv-icon="aui-icon-help" lvTooltipTheme="light" class="configform-constraint"
               [lv-tooltip]="scriptToolTip" lvColorState="true">
            </i>
          </lv-form-label>
          <lv-form-control [lvErrorTip]="scriptErrorTip">
            <input
              formControlName="preScript"
              [placeholder]="scriptPlaceholder"
              lv-input
            />
          </lv-form-control>
        </lv-form-item>
        <lv-form-item>
          <lv-form-label>
            {{ 'protection_restore_post_script_label' | i18n }}
            <i lv-icon="aui-icon-help" lvTooltipTheme="light" class="configform-constraint"
               [lv-tooltip]="scriptToolTip" lvColorState="true">
            </i>
          </lv-form-label>
          <lv-form-control [lvErrorTip]="scriptErrorTip">
            <input
              formControlName="postScript"
              [placeholder]="scriptPlaceholder"
              lv-input
            />
          </lv-form-control>
        </lv-form-item>
        <lv-form-item>
          <lv-form-label>
            {{ 'protection_restore_fail_script_label' | i18n }}
            <i lv-icon="aui-icon-help" lvTooltipTheme="light" class="configform-constraint"
               [lv-tooltip]="scriptToolTip" lvColorState="true">
            </i>
          </lv-form-label>
          <lv-form-control [lvErrorTip]="scriptErrorTip">
            <input
              formControlName="executeScript"
              [placeholder]="scriptPlaceholder"
              lv-input
            />
          </lv-form-control>
        </lv-form-item>
      </lv-collapse-panel>
    </lv-collapse>
  </div>
</lv-form>

<ng-template #titleTpl>
  <lv-group lvGutter="8px">
    <span class="custom-collapse-title-text">{{
      'common_advanced_label' | i18n
      }}</span>
    <i
      lv-icon="aui-icon-help"
      lvTooltipTheme="light"
      lv-tooltip="{{'protection_fileset_restore_script_windows_tips_label'|i18n}}"
      lvColorState="true"
    >
    </i>
  </lv-group>
</ng-template>
